package com.xuqm.sdhbwfu.app.ui

import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.xuqm.base.adapter.CommonAdapter
import com.xuqm.base.adapter.ViewHolder
import com.xuqm.base.ui.BaseActivity
import com.xuqm.sdhbwfu.app.R
import com.xuqm.sdhbwfu.app.databinding.ActivityEnterYlBinding
import com.xuqm.sdhbwfu.app.model.YlListModel
import com.xuqm.sdhbwfu.app.viewmodel.InspectionViewModel

/***
 * 演练入口
 * */
class YLEnterActivity : BaseActivity<ActivityEnterYlBinding>() {
    override fun getLayoutId(): Int =
        R.layout.activity_enter_yl

    override fun fullscreen(): Boolean = true

    private val vm: InspectionViewModel by viewModels()
    private val mData = mutableListOf<YlListModel>()

    private var current = 1

    override fun initData() {
        super.initData()
        mData.add(
            YlListModel(
                "CMBC-EP-YJYL-210630-001",
                "【应急】中压系统供电异常演练-10KV 1#市电供电中断",
                "2021-06-15"
            )
        )
        mData.add(
            YlListModel(
                "CMBC-EP-YJYL-210629-003",
                "【应急】中压系统供电异常演练-10KV双路市电供电中断",
                "2021-06-16"
            )
        )
        mData.add(
            YlListModel(
                "CMBC-EP-YJYL-210629-002",
                "【应急】中压系统供电异常演练-10KV Ⅰ段母线故障",
                "2021-06-17"
            )
        )
        mData.add(
            YlListModel(
                "CMBC-EP-YJYL-210620-001",
                "【应急】UPS系统供电异常应急演练-UPS并机系统单机逆变故障关机",
                "2021-06-18"
            )
        )
        adapter.notifyDataSetChanged()
    }


    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        binding.inspectionBackLyt.setOnClickListener {
            finish()
        }
        binding.inspectionListRv.layoutManager = LinearLayoutManager(mContext)
        binding.inspectionListRv.adapter = adapter
    }

    private val adapter =
        object : CommonAdapter<YlListModel>(R.layout.item_yl_enter_1, mData) {
            override fun convert(holder: ViewHolder, item: YlListModel, position: Int) {
                holder.setText(R.id.item_job_no, item.no)
                holder.setText(R.id.item_job_desc, item.desc)
                holder.setText(R.id.item_job_data, item.date)
                holder.setClickListener(R.id.item_app) {
                    startActivity(Intent(mContext, YLEnterDetailActivity::class.java)
                        .apply {
                            putExtra("data", item)
                        }
                    )
                }
            }

        }

}